package Map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class demo01 {
    //Map<K,V>
    public static void main(String[] args) {
        m6();
    }

    private static void m6() {
        Map<String,String > map = new HashMap<>();
        map.put("gdg","yq");
        map.put("zxc","wmd");
        map.put("123","456");
        //遍历--2
        //1.把集合中的entry对象存入集合
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        //2.遍历获取每一个entry对象
        for (Map.Entry<String, String> i :entrySet) {
            //3.使用entry对象方法  getkey(),getvalue().
            String key = i.getKey();
            String value = i.getValue();
            System.out.println(key + ":" + value);

        }
    }

    private static void m5() {
        //遍历--1
        Map<String,String > map = new HashMap<>();
        map.put("gdg","yq");
        map.put("zxc","wmd");
        map.put("123","456");

        //1.使用keyset()方法把key集合起来
        Set<String> keys = map.keySet();
        //2.遍历set集合
        for (String i : keys){
            //3.使用map的get方法，通过key找到value
            String value = map.get(i);
            System.out.println(value);
        }

    }

    private static void m4() {
        Map<String,String > map = new HashMap<>();
        map.put("gdg","yq");
        map.put("zxc","wmd");
        map.put("123","456");

        boolean gdg = map.containsKey("gdg");
        System.out.println(gdg);

    }

    private static void m3() {
        Map<String,String > map = new HashMap<>();
        map.put("gdg","yq");
        map.put("zxc","wmd");
        map.put("123","456");

        String gdg = map.get("gdg");
        System.out.println(gdg);
    }

    private static void m2() {
        Map<String,String > map = new HashMap<>();
        map.put("gdg","yq");
        map.put("zxc","wmd");
        map.put("123","456");
        System.out.println(map);

        map.remove("123");
        System.out.println(map);

    }

    private static void m1() {
        Map<String,String > map = new HashMap<>();
        map.put("gdg","yq");
        map.put("zxc","wmd");
        map.put("123","456");
        System.out.println(map);
    }
}
